﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace H04
{
    class Program
    {
        static void Main(string[] args)
        {
            double x1 = 0;
            double x2 = 0;

            Console.WriteLine("求 ax^2+bx+c=0 的解");
            Console.Write("请输入a的值：");
            double a = Convert.ToInt32(Console.ReadLine());
            Console.Write("请输入b的值：");
            double b = Convert.ToInt32(Console.ReadLine());
            Console.Write("请输入c的值：");
            double c = Convert.ToInt32(Console.ReadLine());

            double m = b * b - 4 * a * c; 

            if (m < 0)
            {
                Console.WriteLine("此方程无实数解.");
            }
            else if (m == 0)
            {
                x1 = -b / 2 * a;
                Console.WriteLine("方程的解为：x1=x2={0} " , x1);  
            }
            else
            {
                x1 = (-b + Math.Sqrt(m)) / 2 * a;
                x2 = (-b - Math.Sqrt(m)) / 2 * a;
                Console.WriteLine("方程的解为：x1={0}, x2= {1}",x1,x2 );
            }

            Console.ReadKey();
        }
    }
}
